// pages/community/community.js
var app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {

        textmax:300,

        information:[
            "最新教师资格证资讯",
            "关于英语四六级你不可不知的消息",
            "贾老师教你学会各种考试技巧",
            "甄贾老师齐上阵，教资必过",
        ],

        img:'',
        name:'',

        good_icon:"/icon/good2.png",
        like_icon:'/icon/like2.png',
        islike:"收藏",
        id:''

        
    },

    onShow:function(){
        // 显示文本（并）
        // var _this = this;
        // var is = _this.data.post_details.length
        // console.log(is)
        // for(var i=0;i<is;i++){
        //     var textnum = _this.data.post_details[i].text.length
        // }
        

        // if(this.data.post_details[0].text >= this.data.textmax){

        // }

        

        var that=this
        that.setData({
            img:app.globalData.user_head_imgPath,
            name:app.globalData.user_head_name
        })

        
        wx.request({
          url: app.globalData.url+'/f',
          method:'GET',
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          success(res) {
            console.log(res.data.data)
            that.setData({
                list:res.data.data,
            })
          }
        })
    },

    // 跳转到搜索详情界面
    search:function(){
        wx.navigateTo({
            url:'/pages/search/search'
        })
    },

    add_post:function(){
        wx.navigateTo({
          url: '/pages/add_post/add_post',
        })
    },

    go_detail:function(event){
        wx.navigateTo({
          url: '/pages/post_details/post_details',
        })
        console.log(event.currentTarget)
        wx.setStorage({
            key:'which',
            data:event.currentTarget.dataset.id
        })
    },

    add_comment:function(event){
        wx.navigateTo({
          url: '/pages/add_comment/add_comment',
        })
        console.log(event.currentTarget)
        wx.setStorage({
            key:'which',
            data:event.currentTarget.dataset.id
        })
    }, 
    handele_good:function(event){
        this.setData({
            good_icon:"/icon/good1.png"
        })
        wx.setStorage({
            key:'which',
            data:event.currentTarget.dataset.id
        })
        wx.request({
          url: app.globalData.url+'/i',
          method: 'POST',
        data: {
            id:wx.getStorageSync('which')
        },
        header: {
            'content-type': 'application/x-www-form-urlencoded'
        },
     success(res) {
       console.log('success')
     }
        })
    },
    handle_like:function(event){
        // if(this.data.like_icon == '/icon/like1.png'){
        //     this.setData({
        //         like_icon:'/icon/like2.png',
        //         islike:'收藏'
        //     })
        // }else{
        //     this.setData({
        //         like_icon:'/icon/like1.png',
        //         islike:'已收藏'
        //     }) 
        // }

        this.setData({
            like_icon:'/icon/like1.png',
        })

        wx.setStorage({
            key:'which',
            data:event.currentTarget.dataset.id
        })

        //  // 获取的帖子which
        //  var c_which = wx.getStorageSync('which');
        //  console.log(c_which);  

        // //  获取帖子id
        // const query = wx.createSelectorQuery()
        // query.select('#38').boundingClientRect();
        // query.exec((res) => {
        //     console.log(res)
        // })



        wx.request({
          url: app.globalData.url+'/j',
          method: 'POST',
        data: {
            id:wx.getStorageSync('which')
        },
        header: {
            'content-type': 'application/x-www-form-urlencoded'
        },
        success(res) {
            console.log('success')
        }
        })
    }

})